package o;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.RelativeLayout.LayoutParams;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView.a;
import androidx.recyclerview.widget.RecyclerView.s;
import com.huawei.appgallery.forum.base.card.bean.Section;
import java.util.ArrayList;
import java.util.List;
import o.bun.d;
import o.bun.e;

public class buo extends a {
    private final Context ˊ;
    private int ˋ;
    private int ˎ;
    private List<Section> ˏ;
    private OnGlobalLayoutListener ॱ = null;

    public buo(Context context) {
        this.ˊ = context;
        this.ˏ = new ArrayList();
        ॱ();
    }

    @NonNull
    public s ˎ(@NonNull ViewGroup viewGroup, int i) {
        s o_bvd = new bvd(LayoutInflater.from(viewGroup.getContext()).inflate(d.ॱˎ, viewGroup, false));
        if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
            o_bvd.ˊ.setLayoutDirection(1);
        }
        return o_bvd;
    }

    public void ॱ(@NonNull s sVar, int i) {
        if ((sVar instanceof bvd) && this.ˏ != null && this.ˏ.size() > 0) {
            ˋ((bvd) sVar, i, this.ˏ);
        }
    }

    private void ˋ(final bvd o_bvd, int i, List<Section> list) {
        if (list != null && list.size() > 0) {
            final Section section = (Section) list.get(i);
            if (section != null) {
                eqx.ˏ(o_bvd.ॱᐝ, section.ॱ(), "app_default_icon");
                o_bvd.ᐝॱ.setText(section.ˏ());
                o_bvd.ʻॱ.setText(bst.ॱ(this.ˊ, section.ˎ()));
                o_bvd.ʼॱ.setText(bst.ॱ(this.ˊ, (long) section.ʻ()));
                o_bvd.ॱˋ.setOnClickListener(new evx(this) {
                    final /* synthetic */ buo ˋ;

                    public void ˋ(View view) {
                        cil.ˋ(this.ˋ.ˊ, new cim.a().ˊ(section.ॱॱ()).ˋ());
                        bvf.ˋ().ˊ(this.ˋ.ˊ, section, o_bvd.ʼॱ);
                    }
                });
                o_bvd.ॱᐝ.setOnClickListener(new evx(this) {
                    final /* synthetic */ buo ˋ;

                    public void ˋ(View view) {
                        cil.ˋ(this.ˋ.ˊ, new cim.a().ˊ(section.ॱॱ()).ˋ());
                        bvf.ˋ().ˊ(this.ˋ.ˊ, section, o_bvd.ʼॱ);
                    }
                });
                o_bvd.ॱᐝ.setContentDescription(section.ˏ());
            }
            int ॱ = ((azb.ॱ(this.ˊ) - (this.ˎ * (this.ˋ + 1))) - this.ˊ.getResources().getDimensionPixelSize(e.ˏ)) / this.ˋ;
            MarginLayoutParams marginLayoutParams = (MarginLayoutParams) o_bvd.ˊ.getLayoutParams();
            if (marginLayoutParams != null) {
                marginLayoutParams.width = ॱ;
                ˏ(i, marginLayoutParams);
                o_bvd.ˊ.setLayoutParams(marginLayoutParams);
                o_bvd.ॱᐝ.setLayoutParams(new LayoutParams(ॱ, ॱ));
            }
            ˋ(o_bvd);
        }
    }

    private void ˋ(final bvd o_bvd) {
        this.ॱ = new OnGlobalLayoutListener(this) {
            final /* synthetic */ buo ˏ;

            public void onGlobalLayout() {
                if (this.ˏ.ॱ != null) {
                    o_bvd.ˊ.getViewTreeObserver().removeOnGlobalLayoutListener(this.ˏ.ॱ);
                }
                if (o_bvd.ʽॱ.getWidth() < o_bvd.ʿ.getWidth()) {
                    o_bvd.ʽॱ.setVisibility(8);
                    o_bvd.ʼॱ.setVisibility(8);
                    return;
                }
                o_bvd.ʽॱ.setVisibility(0);
                o_bvd.ʼॱ.setVisibility(0);
            }
        };
        o_bvd.ˊ.getViewTreeObserver().addOnGlobalLayoutListener(this.ॱ);
    }

    private void ˏ(int i, MarginLayoutParams marginLayoutParams) {
        marginLayoutParams.setMarginEnd(0);
        if (i == 0) {
            marginLayoutParams.setMarginStart(azb.ˊ(this.ˊ));
            return;
        }
        if (i == ˏ() - 1) {
            marginLayoutParams.setMarginEnd(azb.ˊ(this.ˊ));
        }
        marginLayoutParams.setMarginStart(azb.ˊ(this.ˊ));
    }

    public void ˏ(List<Section> list) {
        this.ˏ = list;
        ˊ();
    }

    public int ˏ() {
        return this.ˏ == null ? 0 : this.ˏ.size();
    }

    private void ॱ() {
        if (epv.ˏॱ(this.ˊ)) {
            this.ˋ = 7;
        } else if (epv.ʼ(this.ˊ)) {
            this.ˋ = 3;
        } else {
            this.ˋ = 6;
        }
        this.ˎ = azb.ˊ(this.ˊ);
    }
}
